package advanced.design_mode.observermode;

import java.util.ArrayList;
import java.util.List;


/**
 * 被观察者, 主题
 */
public class Subject {
    protected List<Observer> list = new ArrayList<>();

    public void register(Observer observer) {
        list.add(observer);
    }

    public void removeRegister(Observer observer) {
        list.remove(observer);
    }

    //通知所有的观察者更新状态
    public void notifyAllObservers() {
        for (Observer observer : list) {
            observer.update(this);
        }
    }

}
